﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace Bit.Art.Core.Models
{
    [Serializable]
    public struct Tick : ISerializable
    {
        public decimal Price { get; set; }

        public decimal Volume { get; set; }

        public decimal LatestBid { get; set; }

        public decimal LatestAsk { get; set; }

        public long Timestamp { get; set; }

        public string Market { get; set; }

        /// <summary>
        /// 成交的方向
        /// </summary>
        public uint Side { get; set; }

        #region ISerializable成员
        public Tick(SerializationInfo info, StreamingContext context)
        {
            Price = (decimal)info.GetValue("p", typeof(decimal));
            Volume = (decimal)info.GetValue("v", typeof(decimal));
            LatestBid = (decimal)info.GetValue("b", typeof(decimal));
            LatestAsk = (decimal)info.GetValue("a", typeof(decimal));
            Timestamp = (long)info.GetValue("t", typeof(long));
            Market = (string)info.GetString("m");
            Side = info.GetUInt32("s");
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("p", Price);
            info.AddValue("v", Volume);
            info.AddValue("b", LatestBid);
            info.AddValue("a", LatestAsk);
            info.AddValue("t", Timestamp);
            info.AddValue("m", Market);
            info.AddValue("s", Side);
        }
        #endregion
    }
}
